//
//  FirstTableViewCell.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/7/2.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "FirstTableViewCell.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
@implementation FirstTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self getUI];
    }
    return self;
}

- (void)getUI
{
    UIImageView *firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, (SCREEN_WIDTH - 30)/2+5, SCREEN_WIDTH/3)];
    UIImage *firstImage = [UIImage imageNamed:@"detailtwo.jpg"];
    firstImageView.image = firstImage;
    firstImageView.tag = 1001;
    firstImageView.backgroundColor = [UIColor redColor];
    firstImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *firstTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(firstTapAction)];
    [firstImageView addGestureRecognizer:firstTap];
    [self.contentView addSubview:firstImageView];
    
    
    UIImageView *goodCarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(firstImageView.frame.size.width - firstImageView.frame.size.height/3, 2 * firstImageView.frame.size.height/3, firstImageView.frame.size.height/3 - 5, firstImageView.frame.size.height/3 - 5)];
    //    goodCarImageView.backgroundColor = [UIColor redColor];
    UIImage *goodCarImage = [UIImage imageNamed:@"shouyecar.png"];
    goodCarImageView.image = goodCarImage;
    goodCarImageView.userInteractionEnabled = YES;
    goodCarImageView.contentMode = UIViewContentModeScaleAspectFit;
    UITapGestureRecognizer *goodTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goodTapAction:)];
    [goodCarImageView addGestureRecognizer:goodTap];
    [firstImageView addSubview:goodCarImageView];
    
    
    
    UILabel *priceLabel  = [[UILabel alloc] initWithFrame:CGRectMake(0, firstImageView.frame.origin.y + firstImageView.frame.size.height/2, firstImageView.frame.size.width, firstImageView.frame.size.height/6)];
    NSString *str = @"￥";
    priceLabel.text = @"1.00/1个";
    priceLabel.text = [str stringByAppendingString:priceLabel.text];
    priceLabel.font = [UIFont systemFontOfSize:14];
    //    priceLabel.backgroundColor = [UIColor redColor];
    priceLabel.textColor = [UIColor colorWithRed:255.0/255.0 green:205.0 / 255.0 blue:0 / 255.0 alpha:1];
    [firstImageView addSubview:priceLabel];
    
    
    UILabel *oldPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, priceLabel.frame.origin.y + priceLabel.frame.size.height, 2 * priceLabel.frame.size.width/3, priceLabel.frame.size.height/2)];
    oldPriceLabel.text = @"原价: ￥5.00/1个";
    //    oldPriceLabel.text = [str stringByAppendingString:oldPriceLabel.text];
    oldPriceLabel.font = [UIFont systemFontOfSize:12];
    oldPriceLabel.textColor = [UIColor whiteColor];
    //    oldPriceLabel.backgroundColor = [UIColor redColor];
    oldPriceLabel.userInteractionEnabled = YES;
    [firstImageView addSubview:oldPriceLabel];
    
    
    UILabel *firstLine = [[UILabel alloc] initWithFrame:CGRectMake(0, oldPriceLabel.frame.size.height/2, oldPriceLabel.frame.size.width, 1)];
    firstLine.backgroundColor = [UIColor whiteColor];
    [oldPriceLabel addSubview:firstLine];
    
    UILabel *firstName = [[UILabel alloc] initWithFrame:CGRectMake(0, oldPriceLabel.frame.origin.y + oldPriceLabel.frame.size.height, 2 * firstImageView.frame.size.width/3, goodCarImageView.frame.size.height)];
    firstName.text = @"美国特级红蛇果";
    //    firstName.backgroundColor = [UIColor yellowColor];
    firstName.font = [UIFont systemFontOfSize:14];
    firstName.textColor = [UIColor whiteColor];
    [firstImageView addSubview:firstName];
    
    UIImageView *secondView = [[UIImageView alloc] initWithFrame:CGRectMake(5, firstImageView.frame.origin.y + firstImageView.frame.size.height + 5, firstImageView.frame.size.width, firstImageView.frame.size.height)];
    secondView.backgroundColor = [UIColor redColor];
    UIImage *secondImage = [UIImage imageNamed:@"detailsix.jpg"];
    secondView.image = secondImage;
    secondView.tag = 1002;
    secondView.userInteractionEnabled = YES;
    UITapGestureRecognizer *secondTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(secondTapAction)];
    [secondView addGestureRecognizer:secondTap];
    [self.contentView addSubview:secondView];
    
    
    UIImageView *goodCarsecondImageView = [[UIImageView alloc] initWithFrame:CGRectMake(secondView.frame.size.width - secondView.frame.size.height/3, 2 * secondView.frame.size.height/3, secondView.frame.size.height/3 - 5, secondView.frame.size.height/3 - 5)];
    UIImage *goodsecondCarImage = [UIImage imageNamed:@"shouyecar.png"];
    goodCarsecondImageView.image = goodsecondCarImage;
    goodCarsecondImageView.userInteractionEnabled = YES;
    goodCarsecondImageView.contentMode = UIViewContentModeScaleAspectFit;
    UITapGestureRecognizer *goodsecondTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goodSecondTapAction:)];
    [goodCarsecondImageView addGestureRecognizer:goodsecondTap];
    [secondView addSubview:goodCarsecondImageView];
    
    
    
    UILabel *pricesecondLabel  = [[UILabel alloc] initWithFrame:CGRectMake(0,  secondView.frame.size.height/2, secondView.frame.size.width, secondView.frame.size.height/6)];
    pricesecondLabel.text = @"1.00/1个";
    pricesecondLabel.text = [str stringByAppendingString:pricesecondLabel.text];
    pricesecondLabel.font = [UIFont systemFontOfSize:14];
    //    priceLabel.backgroundColor = [UIColor redColor];
    pricesecondLabel.textColor = [UIColor colorWithRed:255.0/255.0 green:205.0 / 255.0 blue:0 / 255.0 alpha:1];
    [secondView addSubview:pricesecondLabel];
    
    
    UILabel *oldPricesecondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, pricesecondLabel.frame.origin.y + pricesecondLabel.frame.size.height, 2 * pricesecondLabel.frame.size.width/3, pricesecondLabel.frame.size.height/2)];
    oldPricesecondLabel.text = @"原价: ￥5.00/1个";
    //    oldPriceLabel.text = [str stringByAppendingString:oldPriceLabel.text];
    oldPricesecondLabel.font = [UIFont systemFontOfSize:12];
    oldPricesecondLabel.textColor = [UIColor whiteColor];
    //    oldPriceLabel.backgroundColor = [UIColor redColor];
    oldPricesecondLabel.userInteractionEnabled = YES;
    [secondView addSubview:oldPricesecondLabel];
    
    
    UILabel *secondLine = [[UILabel alloc] initWithFrame:CGRectMake(0, oldPricesecondLabel.frame.size.height/2, oldPricesecondLabel.frame.size.width, 1)];
    secondLine.backgroundColor = [UIColor whiteColor];
    [oldPricesecondLabel addSubview:secondLine];
    
    UILabel *secondName = [[UILabel alloc] initWithFrame:CGRectMake(0, oldPricesecondLabel.frame.origin.y + oldPricesecondLabel.frame.size.height, 2 * secondView.frame.size.width/3, goodCarsecondImageView.frame.size.height)];
    secondName.text = @"美国特级红蛇果";
    //    firstName.backgroundColor = [UIColor yellowColor];
    secondName.font = [UIFont systemFontOfSize:14];
    secondName.textColor = [UIColor whiteColor];
    [secondView addSubview:secondName];
    
    
    
    
    UIImageView *thirdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(firstImageView.frame.origin.x + firstImageView.frame.size.width + 5, firstImageView.frame.origin.y, firstImageView.frame.size.width + 5, 2 * SCREEN_WIDTH/3 + 5)];
    thirdImageView.backgroundColor = [UIColor redColor];
    thirdImageView.userInteractionEnabled = YES;
    thirdImageView.tag = 1003;
    UIImage *thirdImage = [UIImage imageNamed:@"detailsix.jpg"];
    thirdImageView.image = thirdImage;
    UITapGestureRecognizer *thirdTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(thirdTapAction)];
    [thirdImageView addGestureRecognizer:thirdTap];
    [self.contentView addSubview:thirdImageView];
    
    
    
    
    UIImageView *goodCarthirdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(thirdImageView.frame.size.width - thirdImageView.frame.size.height/6, 5 * thirdImageView.frame.size.height/6 , thirdImageView.frame.size.height/6 - 5, thirdImageView.frame.size.height/6 - 5)];
    UIImage *goodthirdCarImage = [UIImage imageNamed:@"shouyecar.png"];
    goodCarthirdImageView.image = goodthirdCarImage;
    goodCarthirdImageView.userInteractionEnabled = YES;
    goodCarthirdImageView.contentMode = UIViewContentModeScaleAspectFit;
    UITapGestureRecognizer *goodthirdTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goodThirdTapAction:)];
    [goodCarthirdImageView addGestureRecognizer:goodthirdTap];
    [thirdImageView addSubview:goodCarthirdImageView];
    
    
    
    UILabel *pricethirdLabel  = [[UILabel alloc] initWithFrame:CGRectMake(0,  5 * thirdImageView.frame.size.height/6, thirdImageView.frame.size.width - goodCarthirdImageView.frame.size.width - 10, thirdImageView.frame.size.height/12)];
    pricethirdLabel.text = @"1.00/1个";
    pricethirdLabel.text = [str stringByAppendingString:pricethirdLabel.text];
    pricethirdLabel.font = [UIFont systemFontOfSize:14];
    //        pricethirdLabel.backgroundColor = [UIColor redColor];
    pricethirdLabel.textAlignment = NSTextAlignmentRight;
    pricethirdLabel.textColor = [UIColor colorWithRed:255.0/255.0 green:205.0 / 255.0 blue:0 / 255.0 alpha:1];
    [thirdImageView addSubview:pricethirdLabel];
    
    
    UILabel *oldPricethirdLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, pricethirdLabel.frame.origin.y + pricethirdLabel.frame.size.height, pricethirdLabel.frame.size.width, pricethirdLabel.frame.size.height/2)];
    oldPricethirdLabel.text = @"原价: ￥5.00/1个";
    //    oldPriceLabel.text = [str stringByAppendingString:oldPriceLabel.text];
    oldPricethirdLabel.font = [UIFont systemFontOfSize:12];
    oldPricethirdLabel.textColor = [UIColor whiteColor];
    //        oldPricethirdLabel.backgroundColor = [UIColor redColor];
    oldPricethirdLabel.textAlignment = NSTextAlignmentRight;
    oldPricethirdLabel.userInteractionEnabled = YES;
    [thirdImageView addSubview:oldPricethirdLabel];
    
    
    UILabel *thirdLine = [[UILabel alloc] initWithFrame:CGRectMake(20, oldPricethirdLabel.frame.size.height/2, oldPricethirdLabel.frame.size.width - 20, 1)];
    thirdLine.backgroundColor = [UIColor whiteColor];
    [oldPricethirdLabel addSubview:thirdLine];
    
    UILabel *thirdName = [[UILabel alloc] initWithFrame:CGRectMake(0, thirdImageView.frame.size.height/3,  thirdImageView.frame.size.width, goodCarthirdImageView.frame.size.height)];
    thirdName.text = @"美国特级红蛇果";
    //    firstName.backgroundColor = [UIColor yellowColor];
    thirdName.font = [UIFont systemFontOfSize:17];
    thirdName.textColor = [UIColor whiteColor];
    thirdName.textAlignment = NSTextAlignmentCenter;
    [thirdImageView addSubview:thirdName];
    
    UILabel *detailName = [[UILabel alloc] initWithFrame:CGRectMake(5, thirdName.frame.origin.y + thirdName.frame.size.height + 5, thirdName.frame.size.width - 10, thirdName.frame.size.height/2)];
    detailName.text = @"外表光鲜亮丽内心红润细腻";
    detailName.font = [UIFont systemFontOfSize:12];
    detailName.backgroundColor = [UIColor colorWithRed:96.0/255.0 green:143.0/255.0 blue:19.0/255.0 alpha:1];
    detailName.textColor = [UIColor whiteColor];
    [thirdImageView addSubview:detailName];
    
    UILabel *tadayLabel = [[UILabel alloc] initWithFrame:CGRectMake(thirdImageView.frame.size.width/5, thirdImageView.frame.size.height/10, 3 * thirdImageView.frame.size.width/5, thirdImageView.frame.size.height/8)];
    tadayLabel.text = @"今 日 抢 鲜 ";
    tadayLabel.textColor = [UIColor whiteColor];
    //    tadayLabel.backgroundColor = [UIColor redColor];
    tadayLabel.font = [UIFont systemFontOfSize:15];
    tadayLabel.textAlignment = NSTextAlignmentCenter;
    [tadayLabel.layer setBorderWidth:1.0];
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 230/255.0, 230/255.0, 230/255.0, 1});
    [tadayLabel.layer setBorderColor:colorref];
    [thirdImageView addSubview:tadayLabel];
    
}

//购物车按钮
- (void)goodTapAction:(UIButton *)button
{
    [self.goodsDelegate goodsCar:button];
    NSLog(@"frr");
}

- (void)goodSecondTapAction:(UIButton *)button
{
    [self.goodsDelegate goodsCar:button];
    NSLog(@"ddddddddf ");
}

- (void)goodThirdTapAction:(UIButton *)button
{
    [self.goodsDelegate goodsCar:button];
}


//详情页面
- (void)firstTapAction
{
    [self.firstDelegate firstImage];
    
}

- (void)secondTapAction
{
    [self.firstDelegate firstImage];
    
}
- (void)thirdTapAction
{
    [self.firstDelegate firstImage];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
